﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientLibrary;

namespace DocumentDigitalization
{
    public partial class UserControl_TemplateBox : UserControl
    {
        SystemState Systemstate;
        Template Template;
        List<TextBox> TextBoxes;
        List<Label> Labels;

        public UserControl_TemplateBox()
        {
            InitializeComponent();
            this.TextBoxes = new List<TextBox>();
            this.Labels = new List<Label>();
        }

        public UserControl_TemplateBox(SystemState systate)
        {
            InitializeComponent();
            this.Systemstate = systate;
            this.TextBoxes = new List<TextBox>();
            this.Labels = new List<Label>();
        }

        public void setSystemState(SystemState systate)
        {
            this.Systemstate = systate;
        }

        public void setTemplate(Template template)
        {
            this.Template = template;
            this.CreateTextboxes();
        }

        public void CreateTextboxes()
        {
            for (int i = 0; i < this.Labels.Count; i++)
            {
                this.Labels[i].Dispose();
            }
            for (int i = 0; i < this.TextBoxes.Count; i++)
            {
                this.TextBoxes[i].Dispose();
            }
            for (int i = 0; i < this.Template.getFields().Count; i++)
            {
                Label lb = new Label();
                lb.Text = this.Template.getFields()[i].Name;
                lb.Width = 40;
                lb.Top = 30 * i + 5;
                lb.Left = 5;
                this.Labels.Add(lb);
                this.Controls.Add(lb);
                TextBox tb = new TextBox();
                tb.Width = 120;
                tb.Top = 30 * i + 5;
                tb.Left = 50;
                tb.Text = this.Template.getFields()[i].Name;
                this.Controls.Add(tb);
                this.TextBoxes.Add(tb);
            }
        }
    }
}
